<?php
/**
 * Bitwise
 *
 * Bitwise operators allow evaluation and manipulation of specific bits
 * within an integer.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_Bitwise extends gop_Base {
    public function execute(gop_Base $_caller = null) {
        if ($this->getReturn()) return;
        $this->setCaller(null);
        $G1 = $this->getContext()->getCallee($this->bit1)->execute($this);
        $G2 = $this->getContext()->getCallee($this->bit2)->execute($this);
        if (!(is_int($G1) && is_int($G2))) {
            die("BitwiseException: bit1 and bit2 must be integer.");
        }
        $_return = null;
        switch($this->op) {
            case "&" : $_return = $G1 & $G2; break;
            case "|" : $_return = $G1 | $G2; break;
            case "^" : $_return = $G1 ^ $G2; break;
            case "<<": $_return = $G1<< $G2; break;
            case ">>": $_return = $G1>> $G2; break;
        }
        $this->setCaller($_caller);
        $this->setResult($_return);
        $this->chainExec();
    }
}
?>